import { Space } from "antd";
import CommonTag from '@/pages/OrderModule/common/components/CommonTag/index.jsx';
import { ClipboardText  } from "@/pages/OrderModule/common/components/CommonText";

//渲染系统订单号
export default function SnRender(props) {
	const { value, record, handleModalOpera } = props;
	const dtk = record['goodsList'].map(v => v['refundStatus']).includes(1);
	const ytk = record['goodsList'].map(v => v['refundStatus']).includes(2);
	const yuncang = record['logisticsList'].map(v => v['logisticsNoSrc']).includes(1);
	const combineMiss = record['goodsList'].findIndex(item => item.missingSubGoods) > -1 ? true: false; //组合装缺失

	const arr = [
		//
		"source",//"手工订单",
		"merge",//"是否合单",
		"split",//"是否拆单",
		"weightSplit",//"是否重量拆单",
		"runVolume",//"是否跑量订单",
		"freightIntercept",//"是否运费拦截",
		"splitBoxState",//"是否拆分装箱",
		"afterSales",//"是否售后",
		"yituikuan",//"已退款",
		"daituikuan",//"待退款",
		"importYuncang",//已导入云仓运单
		"callbackFlag",//物流回传状态
        "missingSubGoods", //组合装缺失
	]
		.reduce((prev, key) => {
			if (key === "daituikuan") {
				dtk && prev.push("daituikuan");
			} else if (key === "yituikuan") {
				ytk && !dtk  && prev.push("yituikuan");
			} else if (key === "importYuncang") {
				yuncang && prev.push("importYuncang");
			} else if (key =="missingSubGoods" ) {
				combineMiss && prev.push("missingSubGoods");  //组合装缺失
            } else if (key === "source") {
				const sourceConfig = {
					'-1': 'shougongpop',
					'1': 'bufa',
					'2': 'huanhuo',
				}
				prev.push(sourceConfig[record[key]]);
			} else if (key === "callbackFlag") {
				const sourceConfig = {
					1: 'yishangchuan',
					2: 'shangchuanshibai',
					3: 'daishagnchuandanhao',
				}
				prev.push(sourceConfig[record[key]]);
			} else if (key === "freightIntercept") {
				const freightInterceptMap = {
					1: "alreadyFreightIntercept",
					2: "cancelFreightIntercept"
				};
				prev.push(freightInterceptMap[record[key]]);
			} else if (record[key]) {
				const keyMap = {
					'merge': "hebingpop",//是否合单
					'runVolume': "paoliangpop",//是否跑量订单
					'split': "chaifenpop",//是否拆单
					'splitBoxState': "wmsSplitOrder",//是否拆分装箱
					'afterSales': "shouhou",//是否售后
					'weightSplit': "chaifenpop",//是否重量拆单
				};
				if (!prev.includes(keyMap[key])) {
					prev.push(keyMap[key]);
				}
			}
			return prev;
		}, [])

	return (
		<>
			<ClipboardText as="s1" text={value}
				link={{
					target: "_blank",
					onClick() {
						handleModalOpera('orderDetail', record)
					}
				}} />
			<Space size={2}>
				{

					arr.map((v, i) => (
						<CommonTag key={i} type={v} />
					))}
			</Space>
		</>
	)
}
